import { EventTouch, Node, view } from 'cc';
import { ccclass, ccmodifier } from '../decorators';
import { BaseView } from './BaseView';
import { Arrays } from '../../../../wing/assets/src';

const Tips = [
    '奔波儿灞，灞波儿奔~',
    '你追我，如果你追上我，我就让你~',
    '我有个苹果，我有个菠萝，嗯~~',
    '是他，是他，就是他，我们的朋友，小哪吒！',
    '大风车吱呀吱哟哟地转，这里的风景真好看~',
    '我想牵着你的手，环游这个星球~',
    '别人笑我太疯癫，我笑他人看不穿！',
    '仰天大笑出门去，我辈岂是蓬蒿人！',
    '我自横刀向天笑，去留肝胆两昆仑！',
    '为有牺牲多壮志，敢教日月换新天！',
];

/**
 * - 作者: DoooReyn
 * - 日期: 2023.10.31
 * - 名称: Dummy
 * - 描述: 视图-新手引导层
 */
@ccclass()
@ccmodifier('Dummy')
export class Dummy extends BaseView {
    protected onEnable(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchScreen, this);
        this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchScreen, this);
        this.node.on(Node.EventType.TOUCH_END, this.onTouchScreen, this);
        this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchScreen, this);
    }

    protected onDisable(): void {
        this.node.off(Node.EventType.TOUCH_START, this.onTouchScreen, this);
        this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchScreen, this);
        this.node.off(Node.EventType.TOUCH_END, this.onTouchScreen, this);
        this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchScreen, this);
    }

    /** 屏幕被点击时调用 */
    protected onTouchScreen(e: EventTouch) {
        if (e.type === Node.EventType.TOUCH_START) {
            // TODO 点击到指定范围后，触发下一步引导，否则无效
            const pos = e.getUILocation();
            if (pos.x >= 0 && pos.y <= view.getVisibleSize().width) {
                this.logger.debug(Arrays.pickOneFrom(Tips));
                e.preventSwallow = true;
                this.logger.debug('允许触摸继续传递');
            } else {
                e.preventSwallow = false;
                e.propagationStopped = true;
                e.propagationImmediateStopped = true;
                this.logger.debug('禁止触摸继续传递');
            }
        } else {
            this.logger.debug('允许触摸继续传递');
            e.preventSwallow = true;
        }
    }

    public async enter() {
        await this.show();
        this.logger.debug('进入舞台');
    }

    async exit() {
        await this.hide();
        this.logger.debug('退出舞台');
    }
}
